<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
key=request.QueryString("key")
mark=request.QueryString("mark")
typeid=request.QueryString("typeid")
hot=request.QueryString("hot")
inventory=request.QueryString("inventory")
sid=request.QueryString("sid")
startTime=request.QueryString("startTime")
EndTime=request.QueryString("EndTime")
search=request.QueryString("search")
if search="搜索" then
	  if key<>"" then
			sqlsearch=sqlsearch+" and (title like '%"&key&"%' or jptitle like '%"&key&"%')"
	  end if
	  if mark<>"" then
			sqlsearch=sqlsearch+" and mark="&mark&""
	  end if
	  if typeid<>"" then
			sqlsearch=sqlsearch+" and ([type]="&typeid&" or [type] in(select id from protype where fid="&typeid&"))"
	  end if
	  if hot<>"" then
			sqlsearch=sqlsearch+" and [hot]="&hot&""
	  end if
	  if inventory<>"" then
			if inventory="0" then sqlsearch=sqlsearch+" and [inventory]=0"
			if inventory="1" then sqlsearch=sqlsearch+" and [inventory]<>0"
	  end if
	  if sid<>"" then
			if sid<>"-1" and sid<>"-2" then sqlsearch=sqlsearch+" and pid in(select pid from Source where istop=1 and sid="&sid&")"
			if sid="-1" then sqlsearch=sqlsearch+" and pid in(select pid from Source where istop=1 and sid in(select sid from shop where typeid=0))"
			if sid="-2" then sqlsearch=sqlsearch+" and pid in(select pid from Source where istop=1 and sid in(select sid from shop where typeid=1))"
	  end if
	  if startTime<>"" and EndTime<>"" then sqlsearch=sqlsearch+" and Convert(char(10),addtime,20)>=Convert(char(10),'"&startTime&"',20) and Convert(char(10),addtime,20)<=Convert(char(10),'"&EndTime&"',20) "
end if
'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by pid desc ) as sortid,* From product) as TempTable where 1=1 and Delflag=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" [PId],[RelationID],[Sort],[Type],[Title],inventory,hot,adminname,[JPtitle],[Weight],[Simple],[Size],[Color],[Bid],[Pic],[Content],[mark],[Delflag],[Addtime],[key],[desc],sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script language="javascript" type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var checkflag = "false";
function checkall(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";}
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";	}
}
//end-->
</script>
</head>

<body>
<div class="main">
  <div class="main-title">查看 <a href="add.asp">添加</a></div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center">
    <form name="form" method="get" action="">
    商品名<input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
    类别
    <select name="typeid" dataType="Require" msg="未选择所用商品类目">
    <option value="">全部分类</option>
    <%
		iic=0
		sub info_typelistc(selecc)
		set rsmtc=conn.execute("select * from protype where fid="&selecc&" order by sort desc")
		do while not rsmtc.eof
		if selecc=0 then
		%>
      <option value="<%=rsmtc("id")%>" <%if typeid=trim(rsmtc("id")) then response.write "selected"%>><%=rsmtc("title")%></option>
      <%
		else
		%>
      <option value="<%=rsmtc("id")%>" <%if typeid=trim(rsmtc("id")) then response.write "selected"%>><%=string(iic*2,"　")%><%=rsmtc("title")%></option>
       <%
		end if
		iic=iic+1
		   info_typelistc(rsmtc("id"))
		iic=iic-1
		rsmtc.movenext
		loop
		set rsmtc=nothing
		end sub
		info_typelistc(0)		
		%>
    </select>
    
    
    是否推荐
    <select name="hot">
      <option value="">全部</option>
      <option value="0" <%if hot="0" then response.Write " selected"%>>否</option>
      <option value="1" <%if hot="1" then response.Write " selected"%>>是</option>
    </select>
    
    
    是否有库存
    <select name="inventory">
      <option value="">全部</option>
      <option value="0" <%if inventory="0" then response.Write " selected"%>>否</option>
      <option value="1" <%if inventory="1" then response.Write " selected"%>>是</option>
    </select>
    
    默认购买来源
    <select name="sid">
        <option value="">全部</option>
        <option value="-1" <%if sid="-1" then response.write "selected"%>>实体店</option>
                    <%		
					set rsnewx=server.CreateObject("adodb.recordset")
					sql="select sid,title from shop where typeid=0"
					rsnewx.open sql,conn,1,3
					if not rsnewx.eof then
					do while not rsnewx.eof 
					%>
					<option value="<%=rsnewx("sid")%>" <%if sid=trim(rsnewx("sid")) then response.write "selected"%>>　<%=rsnewx("title")%></option>
					<%
					rsnewx.movenext
					loop
					rsnewx.close
					set rsnewx=nothing
					end if		 
					%>
         <option value="-2" <%if sid="-2" then response.write "selected"%>>购物网</option> 
                    <%		
					set rsnewx=server.CreateObject("adodb.recordset")
					sql="select sid,title from shop where typeid=1 "
					rsnewx.open sql,conn,1,3
					if not rsnewx.eof then
					do while not rsnewx.eof 
					%>
					<option value="<%=rsnewx("sid")%>" <%if sid=trim(rsnewx("sid")) then response.write "selected"%>>　<%=rsnewx("title")%></option>
					<%
					rsnewx.movenext
					loop
					rsnewx.close
					set rsnewx=nothing
					end if		 
					%>
        </select>
    
    是否上下架
    <select name="mark" id="mark">
      <option value="">全部</option>
      <option value="0" <%if mark="0" then response.Write " selected"%>>下架</option>
      <option value="1" <%if mark="1" then response.Write " selected"%>>上架</option>
    </select>
    
    
    更新日期<input name="StartTime" type="text" class="Wdate" id="startTime" onFocus="var EndTime=$dp.$('EndTime');WdatePicker({doubleCalendar:true,onpicked:function(){EndTime.focus();},maxDate:'#F{$dp.$D(\'EndTime\')}'})" value="<%=startTime%>" size="20" readonly="readonly" /> -
<input name="EndTime" type="text" class="Wdate" id="EndTime" onFocus="WdatePicker({doubleCalendar:true,minDate:'#F{$dp.$D(\'startTime\')}'})" value="<%=EndTime%>" size="20" readonly="readonly" />
    

    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><strong><input type="checkbox" name="checkbox2" onClick="javascript:checkall(this.form);" /> 全选</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Pid</strong></td>
    <td align="center" bgcolor="#FFFFFF">添加者</td>
    <td align="center" bgcolor="#FFFFFF"><strong>中文标题</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>日文标题</strong></td>
    <td align="center" bgcolor="#FFFFFF">重量</td>
    <td align="center" bgcolor="#FFFFFF">库存数量</td>
    <td align="center" bgcolor="#FFFFFF">默认购买来源</td>
    <td align="center" bgcolor="#FFFFFF">颜色</td>
    <td align="center" bgcolor="#FFFFFF">规格</td>
    <td align="center" bgcolor="#FFFFFF"><strong>类目</strong></td>
    <td align="center" bgcolor="#FFFFFF">品牌</td>
    <td align="center" bgcolor="#FFFFFF">是否推荐</td>
    <td align="center" bgcolor="#FFFFFF"><strong>状态</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>操作</strong></td>
    <td bgcolor="#FFFFFF"><strong>添加时间</strong></td>
    </tr>
    <%do while not Rs.eof%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("pid")%>" /></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("Pid")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("adminname")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("title")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("jptitle")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("weight")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("inventory")%></td>
    <td align="center" bgcolor="#FFFFFF">
	<%set rss=conn.execute("select title from shop where sid in(select sid from Source where pid="&rs("pid")&")")
										   if not rss.eof then
										   response.write rss("title")
										   end if
										   set rss=nothing%>
    </td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("color")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("size")%></td>
    <td align="center" bgcolor="#FFFFFF"><%set rss=conn.execute("select title from protype where id="&rs("type"))
										   if not rss.eof then
										   response.write rss("title")
										   end if
										   set rss=nothing%></td>
    <td align="center" bgcolor="#FFFFFF"><%set rss=conn.execute("select title from brand where id="&rs("bid"))
										   if not rss.eof then
										   response.write rss("title")
										   end if
										   set rss=nothing%></td>
    <td align="center" bgcolor="#FFFFFF"><%if rs("hot")="0" then response.Write "否" else response.Write "<font color='red'>是</font>"%></td>
    <td align="center" bgcolor="#FFFFFF"><%if rs("mark")="1" then response.Write "上架" else response.Write "<font color='red'>下架</font>"%></td>
    <td align="center" bgcolor="#FFFFFF">
    
    <a href="add.asp?id=<%=rs("pid")%>">编辑商品</a><br />
    <a href="#" onclick="window.clipboardData.setData('Text', this.title);alert('复制成功')" title="<%=Geturl%>/shopping/<%=rs("pid")%>.html">复制链接</a><br />
    <a href="add.asp?id=<%=rs("pid")%>&copy=yes">复制商品</a><br />
    
    <a target="_blank" href="../daigou/buy.asp?pid=<%=rs("pid")%>&title=<%=server.urlencode(rs("title"))%>&product=buy&a=y">购买商品</a>
    </td>
    <td bgcolor="#FFFFFF"><%=rs("addtime")%></td>
    </tr>
    <%
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="16" align="center" bgcolor="#FFFFFF" class="page">
<input type="submit" name="button" id="button" value="删除" /> <input type="submit" name="button" id="button" value="下架" /> 
      <input type="submit" name="button" id="button" value="上架" />
      <input type="submit" name="button" id="button" value="推荐" />
      <input type="submit" name="button" id="button" value="取消推荐" />
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="16" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
    共 <%=Pager_TotalRecord%> 条 第<%=CurrentPage%>页 / 共 <%=Pager_PageCount%> 页
		<%
		pageurl="key="&key&"&mark="&mark&"&typeid="&typeid&"&hot="&hot&"&inventory="&inventory&"&sid="&sid&"&startTime="&startTime&"&EndTime="&EndTime&"&search="&search&"&"
		if CurrentPage=1 then
			response.Write(" 首页 ")
			response.Write(" 上一页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page=1'>首页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage-1) &"'>上一页</a> ")
		end if
		%>
		<%
		if Clng(CurrentPage)=Clng(Pager_PageCount) then
			response.Write(" 下一页 ")
			response.Write(" 尾页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage+1) &"'>下一页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& Pager_PageCount &"'>尾页</a> ")
		end if
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="mark" value="<%=mark%>" />
        <input type="hidden" name="typeid" value="<%=typeid%>" />
        <input type="hidden" name="hot" value="<%=hot%>" />
        <input type="hidden" name="inventory" value="<%=inventory%>" />
        <input type="hidden" name="sid" value="<%=sid%>" />
        <input type="hidden" name="startTime" value="<%=startTime%>" />
        <input type="hidden" name="EndTime" value="<%=EndTime%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
      </td>
    </tr>
  </table>
</div>
</div>
</body>
</html>
<%
checkbox=request.Form("checkbox")
if checkbox<>"" then	
	if request.Form("button")="删除" then
		'conn.execute("delete from product where pid in("&checkbox&")")
		conn.execute("update product set Delflag=0 where pid in ("&checkbox&")")

	elseif request.Form("button")="下架" then
		conn.execute("update product set mark=0 where pid in ("&checkbox&")")
	
	elseif request.Form("button")="推荐" then
		conn.execute("update product set hot=1 where pid in ("&checkbox&")")
	
	elseif request.Form("button")="取消推荐" then
		conn.execute("update product set hot=0 where pid in ("&checkbox&")")
		
	elseif request.Form("button")="上架" then
		conn.execute("update product set mark=1 where pid in ("&checkbox&")")
	end if
	response.Redirect "view.asp?page="&request.QueryString("page")&""
end if
%>